/**
 * 
 */
package microcredit.gui.table.impl;

import java.awt.Color;
import java.util.Date;

import javax.swing.ImageIcon;

import microcredit.gui.table.EnumBeanTableModel;
import microcredit.model.TrainingType;
import microcredit.model.domain.Status;

enum TrainingColumns {
	COLUMN_SHORT_NAME,
	COLUMN_LONG_NAME,
	COLUMN_STATUS,
	COLUMN_LAST_UPDATE,
}

public final class TrainingTableModel extends
		EnumBeanTableModel<TrainingType, TrainingColumns> {

	@Override
	protected Object getValue(TrainingType bean, TrainingColumns column) {
		switch (column) {
		case COLUMN_SHORT_NAME:
			return bean.getShortName();
		case COLUMN_LONG_NAME:
			return bean.getLongName();
		case COLUMN_STATUS:
			return bean.getStatus() == Status.A ? "Active" : "Inactive";
		case COLUMN_LAST_UPDATE:
			return bean.getUpdateStamp();
		}
		return null;
	}
	
	@Override
	protected Class<?> getValueClass(TrainingColumns column) {
		if (column == TrainingColumns.COLUMN_LAST_UPDATE) {
			return Date.class;
		}
		return super.getValueClass(column);
	}
	
	@Override
	protected Color getForeground(TrainingType o, TrainingColumns column) {
		if (o.getStatus() != Status.A) {
			return Color.RED;
		}
		return super.getForeground(o, column);
	}
	
	@Override
	protected int getWidth(TrainingColumns column) {
		switch (column) {
		case COLUMN_SHORT_NAME:
			return 100;
		case COLUMN_LONG_NAME:
			return 200;
		case COLUMN_STATUS:
			return 50;
		case COLUMN_LAST_UPDATE:
			return 150;
		}
		return super.getWidth(column);
	}
	
	@Override
	public ImageIcon getRowIcon() {
		return new ImageIcon(TrainingTableModel.class.getResource("/microcredit/icons/x16/blackboard.png"));
	}

	@Override
	protected String getName(TrainingColumns column) {
		switch (column) {
		case COLUMN_SHORT_NAME : return "Short name";
		case COLUMN_LONG_NAME : return "Name";
		case COLUMN_STATUS : return "Status";
		case COLUMN_LAST_UPDATE : return "Last update";
		}
		return "";
	}
}